package com.sxkawzp.area.controller;

import com.sxkawzp.area.common.R;
import com.sxkawzp.area.domain.AdministrativeDivision;
import com.sxkawzp.area.request.AdministrativeDivisionForm;
import com.sxkawzp.area.service.AreaService;
import com.sxkawzp.area.vo.TreeAdministrativeDivisionVO;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author suxingkang
 * @version 1.0
 * @since 2025/1/21 9:02
 */
@RestController
@RequestMapping("/area")
public class AreaController {

    @Resource
    private AreaService areaService;

    /**
     * 根据区划code查详情
     */
    @PostMapping("/query/area/code")
    public R<AdministrativeDivision> findByCodeArea(String areaCode) {
        return R.ok(areaService.findByCodeArea(areaCode));
    }

    /**
     * 根据编码查询树级结构
     *
     * @param areaCode 根级别 区划编码
     * @return 区划树
     */
    @PostMapping("/tree")
    public R<TreeAdministrativeDivisionVO> findAllAreaTree(String areaCode) {
        return R.ok(areaService.findAllAreaTree(areaCode));
    }


    /**
     * 区划添加
     *
     * @param request 请求参数
     * @return 是否添加成功
     */
    @PostMapping("/insert")
    public R<Boolean> insertArea(AdministrativeDivisionForm request) {
        return R.ok(areaService.insertArea(request));
    }


    /**
     * 区划添加
     *
     * @param request 请求参数
     * @return 是否添加成功
     */
    @PostMapping("/update")
    public R<Boolean> updateArea(AdministrativeDivisionForm request) {
        return R.ok(areaService.updateArea(request));
    }


    /**
     * 根据区划code查区划全路径
     *
     * @param areaCode 区划code
     */
    @PostMapping("/query/all/path")
    public R<List<AdministrativeDivision>> queryAllPathByAreaCode(String areaCode) {
        return R.ok(areaService.queryAllPathByAreaCode(areaCode));
    }


}
